package org.example.prototype;

import java.util.HashMap;
import java.util.Map;

// 原型注册表 - 存储和管理原型对象
public class ShapeRegistry {
    private static final Map<String, Shape> prototypes = new HashMap<>();

    static {
        // 初始化注册原型
        prototypes.put("defaultCircle", new Circle("红色", 10));
        prototypes.put("defaultRectangle", new Rectangle("蓝色", 20, 15));
    }

    // 添加原型
    public static void addPrototype(String key, Shape prototype) {
        prototypes.put(key, prototype);
    }

    // 获取原型克隆
    public static Shape getPrototype(String key) {
        Shape prototype = prototypes.get(key);
        if (prototype != null) {
            return prototype.clone();
        }
        return null;
    }
}